package com.hyt.it.ogt.ks.service.impl;

import javax.annotation.Resource;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.hyt.it.ogt.ks.model.dto.InitPaperDataNewStatusDTO;
import com.hyt.it.ogt.ks.service.IAsyncService;
import com.hyt.it.ogt.ks.service.IPaperInitService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author liuhh
 */
@Slf4j
@Service
public class AsyncServiceImpl implements IAsyncService {
    @Resource
    private IPaperInitService iPaperInitService;

    @Async("executor")
    @Override
    public void initPaper(String examId, String candidateId) {
        try {
            //最后一个参数为null时，方法中还是会进行判断，不影响
            InitPaperDataNewStatusDTO ps = iPaperInitService.isInitAndNewPaper(examId, candidateId);
            // 未初始化
            if (ps.getRefreshInitPaper()) {
                //初始化考生答案表结构
                iPaperInitService.initPaper(examId, candidateId, 0, ps);
            }
            //已初始化了，不论什么逻辑不提前处理
        } catch (Exception e) {
            log.error("{}", e);
        }
    }
}
